<template>
  <el-dialog
    :title="form.id?'编辑':'新增'"
    :visible.sync="dialogVisible"
    :before-close="close"
    width="30%"
  >
    <el-form label-width="120px">
      <el-form-item label="党内职务名称">
        <el-input v-model="form.name" size="mini" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input
          v-model="form.remark"
          size="mini"
          type="textarea"
          :rows="3"
        />
      </el-form-item>
      <el-form-item label="状态">
        <el-radio-group v-model="form.status">
          <el-radio label="1">启用</el-radio>
          <el-radio label="2">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { add, edit } from '@/api/partyMemberManagement/partyPositions'
export default {
  data () {
    return {
      dialogVisible: false,
      form: {}
    }
  },
  methods: {
    open (row) {
      this.form = { ...row }
      this.dialogVisible = true
    },
    confirm () {
      let submitForm = add
      if (this.form.id) {
        submitForm = edit
      }
      submitForm(this.form).then((res) => {
        this.$message.success('保存成功')
        this.$emit('getData')
        this.close()
      })
    },
    close () {
      this.form = {}
      this.dialogVisible = false
    }
  }
}
</script>
